package com.shu.auth.controller;

import com.alibaba.druid.pool.DruidDataSource;
import com.shu.auth.common.JsonData;
import com.shu.auth.dao.SysAclMapper;
import com.shu.auth.dto.DeptLevelDto;
import com.shu.auth.service.IDeptService;
import com.shu.auth.service.ITreeService;
import com.shu.auth.vo.DeptVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/sys/dept")
@Slf4j
public class SysDeptController {

    @Autowired
    private SysAclMapper sysAclMapper;
    @Autowired
    private IDeptService deptService;

    @Autowired
    private ITreeService treeService;

    @RequestMapping("/save.json")
    @ResponseBody
    public JsonData saveDept(DeptVo deptVo){
        deptService.save(deptVo);
        return JsonData.success();
    }

    @RequestMapping("/tree.json")
    @ResponseBody
    public JsonData tree(){
        List<DeptLevelDto> deptLevelDtoList = treeService.deptTree();
        return JsonData.success(deptLevelDtoList);
    }
    @RequestMapping("/update.json")
    @ResponseBody
    public JsonData updateDept(DeptVo deptVo){
        deptService.update(deptVo);
        return JsonData.success();
    }
}
